#!/usr/bin/env python

from sdxf import *
import math

def arc(start_ang, end_ang, radius, centre):
    points = []
    ang = start_ang-0.01
    while ang != end_ang:
        ang += 0.01
        if ang > end_ang:
            ang = end_ang
        x = math.cos(ang) * radius + centre[0]
        y = math.sin(ang) * radius + centre[1]
        points.append((x, y, 0))
    return points

of=2
cutout = arc(-math.pi/2, math.pi/2, 0.75, (-57.3+of, 3.85))
cutout.reverse()

points = [(-60.5,-37.5,0), (60.5,-37.5,0), (60.5,37.5,0), (-60.5,37.5,0),
      (-60.5,15,0), (-57.3+of,15,0), (-57.3+of,12.85,0), (-60.5+of,12.85,0), # slot 1
      (-60.5+of,4.6,0), (-57.3+of,4.6,0)] + cutout + [(-57.3+of,3.1,0), (-60.5+of,3.1,0), # cut
      (-60.5+of,-12.5,0), (-57.3+of,-12.5,0), (-57.3+of,-15,0), (-60.5,-15,0), # slot 2
          (-60.5,-37.5,0)]
d = Drawing()
d.append(Text("EOMA-200: 121mm x 75mm",
                   point=(-22, 30, 0),
                   height=2))
d.append(Text("MiniPCIe",
                   point=(-53, 5, 0),
                   height=2, rotation=-90))
d.append(PolyLine(points=points,closed=1,color=1))
for i in range(8):
    d.append(Rectangle(point=(-60.25+of, 6.2-0.3+i*0.8,0), width=2.3, height=0.6, color=6,
                            solid=Solid(color=2)))
    
for i in range(18):
    d.append(Rectangle(point=(-60.25+of, 2.2-0.3-i*0.8,0), width=2.3, height=0.6, color=6,
                            solid=Solid(color=2)))
 
# Connector Area mark-out
d.append(Text("Optional Connector Area",
                   point=(-20, -30, 0),
                   height=2))
d.append(Text("Centred, 110mm width",
                   point=(-20, -33, 0),
                   height=1))
d.append(Rectangle(point=(-55.5,-37.25,0), width=110, height=20, color=3,
                        solid=Solid(color=2)))

# SO-DIMM
d.append(Text("SO-DIMM I/O Board cut-out Area",
                   point=(-22, -5, 0),
                   height=2))
d.append(Text("Centred, 70mm x 32mm",
                   point=(-22, -7, 0),
                   height=1))
d.append(Rectangle(point=(-35,-16,0), width=70, height=32, color=3,
                        solid=Solid(color=2)))
d.append(Rectangle(point=(-30,-10,0), width=60, height=26, color=3,
                        solid=Solid(color=2)))

# Locking pins
d.append(Text("I/O Board Locking pin",
                   point=(39, 34, 0),
                   height=1))
d.append(Text("(3.0mm dia, 3.0mm down)",
                   point=(39, 32, 0),
                   height=1))
d.append(Circle(center=(57.5,-34,0), radius=1.5, color=5))
d.append(Circle(center=(57.5,34,0), radius=1.5, color=5))

# B2B Connectors
d.append(Text("B2B 2x25pin 0.5mm",
                   point=(57, -16, 0),
                   height=1, rotation=-90))
d.append(Rectangle(point=(55.5,-30,0), width=4, height=15, color=4,
                        solid=Solid(color=2)))
d.append(Text("B2B 2x25pin 0.5mm",
                   point=(57, 6.5, 0),
                   height=1, rotation=-90))
d.append(Rectangle(point=(55.5,-7.5,0), width=4, height=15, color=4,
                        solid=Solid(color=2)))
d.append(Text("B2B 2x25pin 0.5mm",
                   point=(57, 29, 0),
                   height=1, rotation=-90))
d.append(Rectangle(point=(55.5,15,0), width=4, height=15, color=4,
                        solid=Solid(color=2)))
#d.append(sdxf.Text("Inner Diameter: 25.0mm",
#                   point=(-65, 60, 0),
#                   height=3))
d.saveas('eoma200_pcb.dxf')


